package com.example.demo.controller;

import com.example.demo.pojo.PublicFields;
import com.example.demo.pojo.Result;
import com.example.demo.pojo.dto.StorageDTO;
import com.example.demo.pojo.query.StorageQuery;
import com.example.demo.pojo.vo.PageVO;
import com.example.demo.pojo.vo.StorageVO;
import com.example.demo.service.imply.IStorageServiceImply;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/storage")
@Slf4j
@Api(tags = "仓库相关接口")
@RequiredArgsConstructor
@CrossOrigin(origins = {"http://localhost:8080"}, allowCredentials = "true")
public class StorageController {
    private final IStorageServiceImply storageService;
    @ApiOperation("添加仓库")
    @PostMapping("/add")
    public Result addFactor(@RequestBody StorageDTO StorageDTO) {

        storageService.addStorage(StorageDTO, PublicFields.newInstance());

        return Result.success("新增成功");
    }

    @ApiOperation("批量删除仓库")
    @PostMapping("/delete")
    public Result deleteFactor(@RequestBody List<Long> ids){

        storageService.removeBatchByIds(ids);
        return Result.success("删除成功");
    }

    @ApiOperation("修改仓库信息")
    @PostMapping("/update")
    public Result deleteDevice(@RequestBody StorageDTO StorageDTO){

        storageService.updateStorage(StorageDTO, PublicFields.newInstance());

        return Result.success("修改成功");
    }

    @ApiOperation("分页查询")
    @PostMapping("/page")
    public Result<PageVO<StorageVO>> page(StorageQuery factoryQuery) {

        PageVO<StorageVO> factoryVOs = storageService.queryStoragePage(factoryQuery);
        return Result.success(factoryVOs);
    }
}
